package ru.spb.nicetu.altx.mnemo.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

public class ObjectInputStreamWithLoader extends ObjectInputStream {

  private ClassLoader loader;

  public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
      throws IOException {
    super(in);
    this.loader = loader;
  }

  protected Class< ? > resolveClass(ObjectStreamClass desc) throws IOException,
      ClassNotFoundException {
    String name = desc.getName();
    try {
      return Class.forName(name, false, loader);
    } catch (ClassNotFoundException ex) {
      throw ex;
    }
  }

}
